<?php
/**
 * @author zhaofei
 * @package 超级管理员控制器 
 * @createtime 2014-11-25
 * @updatetime 2014-11-25
 * @ps:最高权限用户
 */
namespace System\Controller;
use Think\Controller;
class SuperController extends Controller {
	function __construct(){
		parent::__construct();
		$ranks = session('ranks');
		if($ranks!=1){
			$this->error('对不起你没有权限',U('Login/index'));
		}
	}
    public function index(){
    	$conditions = array('id'=>session('id'));
    	$data = D('Employee')->where($conditions)->find();
    	$this->assign('data',$data);
    	$this->display();
    }

    public function conf(){
        if(IS_POST){
            if(I('post.is_notify_kefu')){
                if(!filter_var(I('post.kefu_email'),FILTER_VALIDATE_EMAIL)){
                    $this->error('邮件格式不正确');
                }
            }
            if(I('post.id')) 
            {
                M('Config')->where(array('id'=>I('post.id')))->save(I('post.'));
            }else{
                M('Config')->add(I('post.'));
            }
            $this->success('操作成功');
        }else{
            $data = M('Config')->find();
            $this->assign('data',$data);
            $this->display();
        }
    }


    public function order(){
        $cons = array();
        if(isset($_GET['st'])){
            $cons['examize_status'] = $_GET['st'] ; 
        }
        if(isset($_GET['month'])){
            $month_s = date('Y-m');
            $cons['write_time'] = array('between',array(strtotime($month_s),time()));
        }
        $model = M('Order'); // 实例化
        $count = $model->where($cons)->count();// 查询满足要求的总记录数
 
        $Page = new \Think\Page($count,5);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show = $Page->show();// 分页显示输出
        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = $model->where($cons)->order('write_time desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('list',$list);// 赋值数据集
    
        $this->assign('page',$show);// 赋值分页输出
        $this->display(); // 输出模板
    }

     //修改密码
    public function password(){
        if(I('post.password')){
            $pass = md5(md5(I('post.password'),true));
            $result = D('Employee')->where(array('id'=>session('id')))->save(array('password'=>$pass));
            if($result){
                $this->success('修改成功，当前用户自动注销',U('Login/logout'));
            }else{
                $this->error('修改失败');
            }
        }else{
            $this->error('密码不能为空');
        }
    }

    public function view($id){
        $data = D('Order')->where(array('id'=>$id))->find();
        // dump($data);
        $this->assign('data',$data);
        $this->display();  
    }


    public function email(){
        if(isset($_GET['id'])){
            D('Email')->delete($_GET['id']);
        }
        $model = M('Email');
        $count = $model->count();
        $Page = new \Think\Page($count,5);
        $show = $Page->show();// 分页显示输出
        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = $model->order('time desc')->
            limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('list',$list);// 赋值数据集

        $this->assign('page',$show);// 赋值分页输出
        $this->display();
    }





}
